package com.linkwechat.common.utils;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * 处理并记录日志文件
 * 
 * @author ruoyi
 */
public class LogUtils
{
    public static String getBlock(Object msg)
    {
        if (msg == null)
        {
            msg = "";
        }
        return "[" + msg.toString() + "]";
    }

    /**
     * 异常消息输出到字符串，方便写入到其他地方
     * @param e
     * @return
     */
    public static String errInfo(Exception e) {
        StringWriter sw = null;
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            // 将出错的栈信息输出到printWriter中
            e.printStackTrace(pw);
            pw.flush();
            sw.flush();
        } finally {
            StreamCloseUtil.closeAllStream(pw,sw);
        }
        return sw.toString();
    }
}
